package com.gdou.login.controller;

import com.gdou.login.service.UserService;
import form.UserForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.HashMap;

/**
 * @ProjectName: login
 * @Package: com.gdou.login.controller
 * @ClassName: UserController
 * @Author: carrymaniac
 * @Description:
 * @Date: 2020/3/3 2:57 下午
 * @Version:
 */
@Controller
@RequestMapping("user")
@Slf4j
public class UserController {
    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @ResponseBody
    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }

    @ResponseBody
    @PostMapping("/login")
    public HashMap<String,Object> login(@RequestBody UserForm userForm){
        @NotNull String password = userForm.getPassword();
        @NotNull String userNumber = userForm.getUserNumber();
        int login = userService.login(userNumber, password);
        HashMap<String,Object> result = new HashMap<>();;
        if(login==1){
            result.put("data","这里可以放你要放的数据");
            result.put("msg","登录成功");
            return result;
        }else {
            result.put("data",null);
            result.put("msg","登录失败");
            return result;
        }
    }
}
